Page({
  data: {
    currentDate: new Date().getTime(),
    houseLayerVisible: false,
    repairLayerVisible: false,
    dateLayerVisible: false,
    houseList: [],
    houseName: '',
    repairItem: [{ name: '水路卫浴' }, { name: '电路灯具' }, { name: '管道疏通' }, { name: '开锁换锁' }],
    attachment: [
      { url: '/repair_pkg/static/uploads/attachment.jpg' },
      { url: '/repair_pkg/static/uploads/attachment.jpg' },
    ],
  },
  openHouseLayer() {
    this.setData({ houseLayerVisible: true })
  },
  closeHouseLayer() {
    this.setData({ houseLayerVisible: false })
  },
  openRepairLayer() {
    this.setData({ repairLayerVisible: true })
  },
  closeRepairLayer() {
    this.setData({
      repairLayerVisible: false,
    })
  },

  openDateLayer() {
    this.setData({ dateLayerVisible: true })
  },
  closeDateLayer() {
    this.setData({ dateLayerVisible: false })
  },
  goList() {
    wx.reLaunch({
      url: '/repair_pkg/pages/list/index',
    })
  },
  // ------ 自己写的代码 -------
  selectHouse(ev) {
    this.setData({
      houseName: ev.detail.name,
    })
  },
  selectRepair(ev) {
    console.log('选择维修项目', ev.detail)
  },
  // 页面加载
  onLoad() {
    // 查询审核通过的房屋
    this.getHouseList()
  },
  // 需查询审核通过的房屋
  async getHouseList() {
    // 注意：这里是 /house (审核通过的房屋列表)，而不是 /room (所有房屋列表)
    const res = await wx.http.get('/house')
    this.setData({
      houseList: res.data,
    })
  },
})
